home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / Dragonsmith 1.0b2 / DalisMaker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-17  |  2.7 KB  |  87 lines

  1. /*
  2.     DalisMaker.c
  3.     
  4.     Makes an 'alis' resource for each thing dropped on it and saves them in a new file
  5.     
  6.     NOTE:    We assume at run-time that if Apple Events are available then the new System 7
  7.             standard file package is also available.  I know I shouldn't, but ╔
  8.     
  9.     Copyright ⌐ 1992 by Paul M. Hoffman
  10.     Send feedback to paul.hoffman@um.cc.umich.edu
  11.     
  12.     This code may be freely used, altered, and distributed in any way you want as long as:
  13.         1.    It is GIVEN away rather than sold;
  14.         2.    This statement and the above copyright notice are left intact.
  15.     
  16.     Created    24 Apr 1992    v0.0        Some code
  17.     Modified                v0.1        Hey, it works!  I hardly had to fix anything!  Creates named
  18.                                     'alis' resources.  Handles replaced files OK.  I'm crossing
  19.                                     my fingers on whether it'll make an alias for a volume ╔
  20.                                 Yes!  It makes an 'alis' resource for a floppy or hard disk that
  21.                                     is identical to the one the Finder makes for it in an alias file
  22.                                     ╤ not tested in a shared environment, however ╔
  23.             17 May 1992    v1.0b1    First release
  24.     
  25. */
  26.                                     
  27. #include    "Dragon.h"
  28. #include    <StandardFile.h>
  29. #include    <Aliases.h>
  30.  
  31. #define    rAliasType            'alis'
  32. #define    kLowNonSystemResID    128
  33.  
  34. class DalisMaker: Dragon {
  35.  
  36.     public:
  37.         virtual OSErr    ProcessDroppings (FSSpec **docs, long numDocs);
  38.  
  39. };
  40.  
  41. OSErr DalisMaker::ProcessDroppings (FSSpec **docs, long numDocs)
  42. {
  43.     StandardFileReply    reply;
  44.     OSErr            err = noErr;
  45.     short            refNum, aliasResID;
  46.     long                i;
  47.     AliasHandle        aliasHndl;
  48.     FSSpec            *fss;
  49.     
  50.     StandardPutFile ("\pSave 'alis' resources in new file:", "\pAliases", &reply);        // Pick a file to save aliases in
  51.     if (reply.sfGood) {
  52.         if (reply.sfReplacing)
  53.             err = FSpDelete (&reply.sfFile);
  54.         if (err == noErr) {
  55.             FSpCreateResFile (&reply.sfFile, 'RSED', 'rsrc', reply.sfScript);        // Create the file
  56.             err = ResError ();
  57.             if (err == noErr) {
  58.                 refNum = FSpOpenResFile (&reply.sfFile, fsCurPerm);            // Open the file
  59.                 err = ResError ();
  60.                 if (err == noErr) {
  61.                     HLock ((Handle) docs);
  62.                     aliasResID = kLowNonSystemResID;        // i.e., 128
  63.                     
  64.                     for (i = numDocs, fss = *docs; i--; fss++) {                // Add each alias to the file
  65.                         NewAlias (NULL, fss, &aliasHndl);
  66.                         if (aliasHndl != NULL)
  67.                             AddResource ((Handle) aliasHndl, rAliasType, aliasResID++, &fss->name);
  68.                     }
  69.                     
  70.                     CloseResFile (refNum);                                // Close the file
  71.                     HUnlock ((Handle) docs);
  72.                 }
  73.             }
  74.         }
  75.     }
  76.         
  77.     inherited::ProcessDroppings (docs, numDocs);
  78. }
  79.  
  80. Dragon *CreateGDragon (void)
  81. {
  82.     // If you want your dragon to do anything, you must override this method
  83.     //    so that it returns an instance of your dragon class ╤ forgetting to
  84.     //    change this method is an easy way to get totally frustrated!
  85.  
  86.     return (Dragon *) new DalisMaker;
  87. }